package com.example.projectcode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.projectcode.mapper.TestMapper;
import com.example.projectcode.model.Test;
import com.example.projectcode.service.TestService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

@Service
public class TestServiceImpl extends ServiceImpl<TestMapper, Test> implements TestService {
    @Override
    public int makePaper(String testName, Integer limitTime) {

        Test test = new Test();
        test.setTestName(testName);
        test.setLimitTime(limitTime);

        LocalDateTime localDateTime = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String dateTime = localDateTime.format(dateTimeFormatter);
        test.setTestRtime(dateTime);

        baseMapper.insert(test);
        Integer testId = test.getTestId();
        return testId;

    }

    @Override
    public List<Test> selectAllTests() {
        return baseMapper.selectList(new QueryWrapper<Test>());
    }

    @Override
    public int deletetestById(Integer testId) {
        return baseMapper.delete(new QueryWrapper<Test>().eq("testid",testId));
    }


}


